package com.navinfo.platform.dataanalysis.dto;

import lombok.Data;
import org.apache.spark.sql.Column;
import org.apache.spark.sql.Row;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;

import static org.apache.spark.sql.functions.col;

@Data
public class EventInfoDto implements Serializable {
    private long uid;
    private long tid;
    private int hsbTimes;
    private int hsbDuration;
    private int hsbMileage;
    private int hsb100kmTimes;
    private int hsbDurationProportion;
    private int hsbMileageProportion;
    private int csbTimes;
    private int csbDuration;
    private int csbMileage;
    private int csb100kmTimes;
    private int csbDurationProportion;
    private int csbMileageProportion;
    private int clutchTimes;
    private int clutchDuration;
    private int clutchMileage;
    private int clutch100kmTimes;
    private int clutchDurationProportion;
    private int clutchMileageProportion;
    private int foutTimes;
    private int foutDuration;
    private int fout100kmTimes;
    private int foutDurationProportion;
    private int idleTimes;
    private int idleDuration;
    private int idle100kmTimes;
    private int idleDurationProportion;
    private int ngTimes;
    private int ngDuration;
    private int ngMileage;
    private int ng100kmTimes;
    private int ngDurationProportion;
    private int ngMileageProportion;
    private int mileage;
    private int duration;
    private Timestamp updateTime;
    private String day;  //分区字段

    public static EventInfoDto parseRow(Row row){
        EventInfoDto eventInfoDto = new EventInfoDto();

        eventInfoDto.setUid(row.getAs("uid"));
        eventInfoDto.setTid(row.getAs("tid"));
        eventInfoDto.setMileage(row.getAs("mileage"));
        eventInfoDto.setDuration(row.getAs("duration"));
        //eventInfoDto.setDay(row.getAs("day"));

        //设置高速刹车统计数据
        eventInfoDto.setHsbTimes(row.getAs("hsb_times"));
        eventInfoDto.setHsbDuration(row.getAs("hsb_duration"));
        eventInfoDto.setHsbMileage(row.getAs("hsb_mileage"));

        //设置普通刹车统计数据
        eventInfoDto.setCsbTimes(row.getAs("csb_times"));
        eventInfoDto.setCsbDuration(row.getAs("csb_duration"));
        eventInfoDto.setCsbMileage(row.getAs("csb_mileage"));

        //设置离合统计数据
        eventInfoDto.setClutchTimes(row.getAs("clutch_times"));
        eventInfoDto.setClutchDuration(row.getAs("clutch_duration"));
        eventInfoDto.setClutchMileage(row.getAs("clutch_mileage"));

        //设置熄火统计数据
        eventInfoDto.setFoutTimes(row.getAs("fout_times"));
        eventInfoDto.setFoutDuration(row.getAs("fout_duration"));

        //设置IDLE统计数据
        eventInfoDto.setIdleTimes(row.getAs("idle_times"));
        eventInfoDto.setIdleDuration(row.getAs("idle_duration"));

        //设置空挡滑行统计
        eventInfoDto.setNgTimes(row.getAs("ng_times"));
        eventInfoDto.setNgDuration(row.getAs("ng_duration"));
        eventInfoDto.setNgMileage(row.getAs("ng_mileage"));
        return eventInfoDto;
    }

    public static Column[] columns(){
        Column uid = col("uid").as("uid");
        Column tid = col("tid").as("tid");
        Column hsbTimes = col("hsbTimes").as("hsb_times");
        Column hsbDuration = col("hsbDuration").as("hsb_duration");
        Column hsbMileage = col("hsbMileage").as("hsb_mileage");
        Column hsb100kmTimes = col("hsb100kmTimes").as("hsb_100km_times");
        Column hsbDurationProportion = col("hsbDurationProportion").as("hsb_duration_proportion");
        Column hsbMileageProportion = col("hsbMileageProportion").as("hsb_mileage_proportion");
        Column csbTimes = col("csbTimes").as("csb_times");
        Column csbDuration = col("csbDuration").as("csb_duration");
        Column csbMileage = col("csbMileage").as("csb_mileage");
        Column csb100kmTimes = col("csb100kmTimes").as("csb_100km_times");
        Column csbDurationProportion = col("csbDurationProportion").as("csb_duration_proportion");
        Column csbMileageProportion = col("csbMileageProportion").as("csb_mileage_proportion");
        Column clutchTimes = col("clutchTimes").as("clutch_times");
        Column clutchDuration = col("clutchDuration").as("clutch_duration");
        Column clutchMileage = col("clutchMileage").as("clutch_mileage");
        Column clutch100kmTimes = col("clutch100kmTimes").as("clutch_100km_times");
        Column clutchDurationProportion = col("clutchDurationProportion").as("clutch_duration_proportion");
        Column clutchMileageProportion = col("clutchMileageProportion").as("clutch_mileage_proportion");
        Column foutTimes = col("foutTimes").as("fout_times");
        Column foutDuration = col("foutDuration").as("fout_duration");
        Column fout100kmTimes = col("fout100kmTimes").as("fout_100km_times");
        Column foutDurationProportion = col("foutDurationProportion").as("fout_duration_proportion");
        Column idleTimes = col("idleTimes").as("idle_times");
        Column idleDuration = col("idleDuration").as("idle_duration");
        Column idle100kmTimes = col("idle100kmTimes").as("idle_100km_times");
        Column idleDurationProportion = col("idleDurationProportion").as("idle_duration_proportion");
        Column ngTimes = col("ngTimes").as("ng_times");
        Column ngDuration = col("ngDuration").as("ng_duration");
        Column ngMileage = col("ngMileage").as("ng_mileage");
        Column ng100kmTimes = col("ng100kmTimes").as("ng_100km_times");
        Column ngDurationProportion = col("ngDurationProportion").as("ng_duration_proportion");
        Column ngMileageProportion = col("ngMileageProportion").as("ng_mileage_proportion");
        Column mileage = col("mileage").as("mileage");
        Column duration = col("duration").as("duration");
        Column updateTime = col("updateTime").as("update_time");
        Column day = col("day").as("day");
        return new Column[]{uid,tid,hsbTimes,hsbDuration,hsbMileage,hsb100kmTimes,hsbDurationProportion,hsbMileageProportion,
                csbTimes,csbDuration,csbMileage,csb100kmTimes,csbDurationProportion,csbMileageProportion,clutchTimes,clutchDuration,
                clutchMileage,clutch100kmTimes,clutchDurationProportion,clutchMileageProportion,foutTimes,foutDuration,fout100kmTimes,
                foutDurationProportion,idleTimes,idleDuration,idle100kmTimes,idleDurationProportion,ngTimes,ngDuration,ngMileage,
                ng100kmTimes,ngDurationProportion,ngMileageProportion,mileage,duration,updateTime, day};
    }

}
